﻿using System;

namespace Core.Ali
{
    public class DescribeDomains
    {

        /**
         * 使用AK&SK初始化账号Client
         * @param accessKeyId
         * @param accessKeySecret
         * @return Client
         * @throws Exception
         */
        public static AlibabaCloud.SDK.Alidns20150109.Client CreateClient(string accessKeyId, string accessKeySecret, string endpoint)
        {
            AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
            {
                // 您的 AccessKey ID
                AccessKeyId = accessKeyId,
                // 您的 AccessKey Secret
                AccessKeySecret = accessKeySecret,
            };
            // 访问的域名
            config.Endpoint = endpoint;
            return new AlibabaCloud.SDK.Alidns20150109.Client(config);
        }

        public static AlibabaCloud.SDK.Alidns20150109.Models.DescribeDomainsResponse GetList(DomainRequest request)
        {
            AlibabaCloud.SDK.Alidns20150109.Client client = CreateClient(request.AppId, request.Secret, request.Endpoint);
            AlibabaCloud.SDK.Alidns20150109.Models.DescribeDomainsRequest describeDomainsRequest = new AlibabaCloud.SDK.Alidns20150109.Models.DescribeDomainsRequest
            {
                PageNumber = request.Page,
                PageSize = request.PageSize,
            };
            if (!string.IsNullOrEmpty(request.Key))
            {
                describeDomainsRequest.KeyWord = request.Key;
                describeDomainsRequest.SearchMode = "LIKE";
            }
            AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
            // 复制代码运行请自行打印 API 的返回值
            var response = client.DescribeDomainsWithOptions(describeDomainsRequest, runtime);
            return response;
        }


        public static AlibabaCloud.SDK.Alidns20150109.Models.DescribeDomainRecordsResponse GetRecordList(DomainRequest request)
        {
            AlibabaCloud.SDK.Alidns20150109.Client client = CreateClient(request.AppId, request.Secret, request.Endpoint);
            AlibabaCloud.SDK.Alidns20150109.Models.DescribeDomainRecordsRequest describeDomainsRequest = new AlibabaCloud.SDK.Alidns20150109.Models.DescribeDomainRecordsRequest
            {
                PageNumber = request.Page,
                PageSize = request.PageSize,
                DomainName = request.DomainName,
            };
            AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
            // 复制代码运行请自行打印 API 的返回值
            var response = client.DescribeDomainRecordsWithOptions(describeDomainsRequest, runtime);
            return response;
        }


    }
}
